package com.olympia.myapp.xml;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.olympia.myapp.util.Constants;

public class LoginXMLHandler extends DefaultHandler {

	Boolean currentElement = false;
	String currentValue = null;
	public List<String> rsLogin = null;

	/**
	 * <?xml version="1.0" encoding="utf-8"?>
	 * <azsoft><LOGIN><RS><result>OK</result ><fullname>luongpp<
	 * /fullname><score>0</score><retest>0</retest><level>TUẦN(Đến 0h
	 * 02-09-2012)
	 * </level><order>-1</order><coin>500</coin></RS></LOGIN></azsoft>
	 */
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		currentElement = true;

		if (localName.equals("RS")) {
			/** Start */
			rsLogin = new ArrayList<String>();
		}
	}

	/**
	 * <azsoft> <LOGIN> <RS> <result>OK</result> <fullname>tatuanvn</fullname>
	 * <score>450</score> <retest>1</retest> <level>TUẦN(Đến
	 * 0h02-09-2012)</level> <order>1</order> <coin>6800</coin> </RS> </LOGIN>
	 * </azsoft>
	 */
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		currentElement = false;

		/** set value */
		if (localName.equalsIgnoreCase("result"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("fullname"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("score"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("retest"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("level"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("order"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("coin"))
			rsLogin.add(currentValue);
		else if (localName.equalsIgnoreCase("deccoin"))
			Constants.STRCOINT = currentValue;

	}

	/**
	 * Called to get tag characters ( ex:- <name>AndroidPeople</name> -- to get
	 * AndroidPeople Character )
	 */
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

		if (currentElement) {
			currentValue = new String(ch, start, length);
			currentElement = false;
		}

	}

}
